#include"../../inc/net/Address.h"
#include<arpa/inet.h>
#include<string>
#include<string.h>

using std::string;

namespace SE
{
    Address::Address(const string& ip, unsigned short port)
    {
        memset(&_addr, 0, sizeof(sockaddr_in));
        _addr.sin_family = AF_INET;
        _addr.sin_addr.s_addr = inet_addr(ip.c_str());
        _addr.sin_port = htons(port);
    }

    Address::Address(const sockaddr_in& addr)
    : _addr(addr)
    {
    }

    sockaddr_in* Address::getAddr()
    {
        return &_addr;
    }

    string Address::getIP() const 
    {
        return string(inet_ntoa(_addr.sin_addr));
    }

    unsigned short Address::getPort() const
    {
        return ntohs(_addr.sin_port);
    }
}

